<?php

namespace App\Admin\Actions\NewsAction;

use App\Models\User;
use Illuminate\Support\Facades\DB;
use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;

class NewsExamine extends RowAction
{
    public $name = '新闻审核';
    
    public function handle(Model $model)
    {
	    /**
	     * @var $model User
	     */
    	
    	if ($model->is_examine) {
    		return $this->response()->success('新闻已审核过了');
	    }

	   
    	
    	DB::transaction(function () use ($model) {
		    $model->update([
			    'is_examine' => true,
		    ]);
	    });
    	
    	
	    return $this->response()->success('新闻审核通过')->refresh();
    }
	
	public function dialog()
	{
		$this->confirm('确定审核通过该新闻吗?');
	}
}
